<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <title>执行风险</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../../../css/mui.min.css" rel="stylesheet" />
    <link href="../css/common.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../../../css/preview.css" />
    <style>
      .uls {
        padding: 20px 20px;
        list-style: none;
        margin: 0;
      }
      
      .mui-table-view:after {
        height: 0;
      }
      
      .titles {
        /* font-weight: bold; */
        margin-bottom: 24px;
      }
      
      .img_s {
        float: left;
        width: 20px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        color: #fff;
        background-color: #0082E6;
        border-radius: 100%;
        /* background: url(../img/word.png) no-repeat; */
        /* background-size: 100%; */
        margin: auto 0;
      }
      
      .bocks {
        padding: 0 5px;
      }
      
      .areas {
        background-color: ##F5F6F7;
        border: solid 1px #DCDCDC;
      }
      
      .imgss {
        float: left;
        margin-right: 10px;
      }
      
      .imgss img {
        width: 100%;
      }
      
      .signs {
        display: inline-block;
        width: 160px;
        height: 160px;
        border: solid 1px #3188FE;
        border-radius: 5px;
        margin-right: 10px;
        margin-bottom: 10px;
        /* background-color: #D4E6FF; */
      }
      
      .uploads {
        display: inline-block;
        width: 160px;
        height: 160px;
        /* border-radius: 5px; */
        background: url(../img/task/dianjipaizhao.png) no-repeat;
        background-size: 100%;
        margin-bottom: 20px;
      }
      
      .submits {
        width: 100%;
        margin-top: 30px;
        height: 4 0px;
        border-radius: 30px;
      }
      /*.fixed-btn .mui-btn{
       width: 30%;
     }*/
      
      .putList {
        display: flex;
        justify-content: space-between;
        padding-bottom: 20px;
      }
      
      .putList input {
        width: 80%;
      }
      
      .mui-grid-view.mui-grid-9 {
        background-color: initial;
        border: none;
      }
      
      .image-warp {
        width: 100%;
        padding-bottom: 100%;
        position: relative;
      }
      
      .image-warp img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
      }
      
      .image-del {
        width: 20px !important;
        font-size: 1.5rem;
        position: absolute;
        top: 0px;
        right: 0px;
      }
      
      .mui-grid-9-item {
        padding: 10px;
      }
      
      .mui-grid-view {
        display: flex;
        flex-wrap: wrap;
      }
      
      .areas {
        background-color: #F1F3F7;
      }
      
      .tips {
        text-align: center;
        font-weight: bold;
        line-height: 40px;
        font-size: 18px;
        border-bottom: 1px solid #DCDCDC;
      }
      
      .option {
        display: flex;
        justify-content: space-around;
        margin-top: 20px;
      }
      
      .option button {
        width: 80px;
      }
      
      .tips-list {
        margin-top: 40%;
      }
      
      .mui-navigate-right:after {
        right: 0;
      }
      
      .screens {
        position: absolute;
        top: 44px;
        left: 0;
        width: 100%;
        min-height: 200px;
        background-color: #fff;
        z-index: 999;
        border-radius: 0;
      }
      
      .square-item {
        width: 30px;
        height: 30px;
        border-radius: 3px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 10px;
        margin-right: 15px;
       background: #F5F6F7;
        color: #333;
      }
      .square-item.bg-blue{
        color: #FFFFFF;
        background: #3188FE;
      }
      .square-item.active {
        border: 1px dashed #004AAF;
      }
      
      .square-item img {
        width: 15px;
        height: 15px;
      }
      
      .action-delete {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 10px;
        background-color: rgba(0, 0, 0, 0.5);
        text-align: center;
        margin: 0 10px;
      }

      .action-delete .mui-icon {
        color: #FFFFFF;
      }
      .radios .rs1 {
        left: 100px;
      }
      
      .radios .rs2 {
        left: 180px;
      }
      
      .oks {
        position: absolute;
        left: 130px;
        top: 10px;
      }
      
      .nos {
        position: absolute;
        left: 210px;
        top: 10px;
      }
    </style>
  </head>

  <body>
    <div id="container">
      <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left text-white"></a>
        <h1 class="mui-title">执行风险</h1>
        <a class="mui-pull-right mui-bar-right" @click="screen">
          <img src="../img/screen.png" width="18" style="margin-right: 3px;" />
          <span> 筛选</span>
        </a>
      </header>
      <div class="mui-content page-wrap" style="background: #FFFFFF;">
        <ul class="uls page-scroll">
          <li class="lis" style="margin-bottom: 20px;">
            <div>
              {{pageIndex + 1}}、{{currentIndex + 1}}/{{allWp.length}} {{detail.position ? '辅助工序': '基本工序'}} 
            </div>
            <div>
              <span>工序编号：</span><span>{{detail.wpCode}}</span>
            </div>
            <div>
              <span>作业项目：</span><span>{{detail.jobProject}}</span>
            </div>
            <div>
              <span>作业方法：</span><span>{{detail.jobMethod}}</span>
            </div>
          </li>
          <li class="lis margin-bottom-sm" v-for="(item,index) in projectList" :key="index" v-cloak>
            <div class="titles">
              <span class="img_s">{{index+1}}</span>
              <span class="bocks">{{item.refInput.name}} {{item.refInput.explain}}：{{inputShowText(item.refInput, dict)}}</span>
            </div>
            <div v-show="!acceptIng">
              <div class="margin-bottom">
                <div>执行人填写：</div>
                <div v-if="item.refInput.typeValue == 'number'"> {{item.value}}&nbsp;{{item.refInput.unitValue}}</div>
                <div v-if="item.refInput.typeValue == 'text'"> {{item.remarks}}</div>
                <div v-if="item.refInput.typeValue == 'boolean'"> {{item.value}}</div>
                <ul class="mui-grid-view mui-grid-9" v-if="item.refInput.typeValue == 'img'">
                  <li class="mui-grid-9-item mui-col-xs-4 mui-col-sm-3 img-item" v-for="(item, i) in item.files">
                    <div class="image-warp">
                      <img :src="serverUrl + item.filePath" :data-preview-src="serverUrl + item.filePath" :data-preview-group="index + '' + 0" alt="" />
                    </div>
                  </li>
                </ul>
              </div>
              <div class="margin-bottom">
                <div>验收填写：</div>
                <div v-if="item.refInput.typeValue == 'number'"> {{item.checkValue}}&nbsp;{{item.refInput.unitValue}}</div>
                <div v-if="item.refInput.typeValue == 'text'"> {{item.checkRemarks}}</div>
                <div v-if="item.refInput.typeValue == 'boolean'"> {{item.checkValue}}</div>
                <ul class="mui-grid-view mui-grid-9" v-if="item.refInput.typeValue == 'img'">
                  <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item" v-for="(item, i) in item.checkFiles">
                    <div class="image-warp">
                      <img :src="serverUrl + item.filePath" :data-preview-src="serverUrl + item.filePath" :data-preview-group="index + '' + 1" alt="" />
                    </div>
                  </li>
                </ul>
              </div>
            </div>

            <div v-show="acceptIng">
              <div v-if="item.refInput.typeValue == 'number'">
                <div class="putList">
                  <div>
                    <input v-model="item.checkValue" type="number" placeholder="请输入" class="val1" maxlength="20"/>{{item.refInput.unitValue}}
                  </div>
                </div>
              </div>
              <div v-if="item.refInput.typeValue == 'boolean'">
                <div class="mui-input-row mui-radio radios">
                  <label>选项(是否)：</label>
                  <input name="radio3" v-model="item.checkValue" type="radio" value="是" class="rs1">
                  <span class="oks">是</span>
                  <input name="radio3" v-model="item.checkValue"  type="radio" value="否" class="rs2">
                  <span class="nos">否</span>
                </div> 
              </div>
              <div v-if="item.refInput.typeValue == 'text'">
                <textarea v-model="item.checkRemarks" name="" class="areas" cols="30" rows="6" id="textarea" placeholder="请输入" maxlength="200"></textarea>
              </div>
              <ul class="mui-grid-view mui-grid-9"  v-if="item.refInput.typeValue == 'img'">
                <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item" v-for="(item, i) in item.checkFiles">
                  <div class="image-warp">
                    <img :src="item.path || (serverUrl + item.filePath)" :data-preview-src="item.path || (serverUrl + item.filePath)" :data-preview-group="index + '' + 2" alt="" />
                  </div>
                  <!--<img src="../img/del.png" class="image-del" @tap="delImg(index,i)"></img>-->
                  <div class="action-delete" @tap="delImg(index,i)" v-if="acceptIng">
                    <span class="mui-icon mui-icon-trash"></span>
                  </div>
                </li>
                <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item">
                  <div class="image-warp">
                    <img src="../img/task/dianjipaizhao.png" alt="" @tap="camera(index)" />
                  </div>
                </li>
              </ul>
            </div>

          </li>
        </ul>
        <div class="fixed-btn" v-if="acceptIng">
          <button type="button" @tap="saveInfo()" class="mui-btn mui-btn-primary margin-right-sm">保存</button>
          <button type="button" @tap="cancel()" class="mui-btn">取消</button>
        </div>
        <div class="fixed-btn" v-else>
          <button type="button" @tap="upInfo()" class="mui-btn margin-right-sm" v-if="pageIndex>0 || currentIndex> 0">上一个</button>
          <button type="button" @tap="acceptIng=true" class="mui-btn mui-btn-primary margin-right-sm" v-if="claimed == 1">执行验收</button>
          <button type="button" @tap="nextInfo()" class="mui-btn mui-btn-primary mui-btn-outlined" v-if="pageIndex<list.length-1 || currentIndex < allWp.length - 1">下一个</button>
        </div>

        <!--<div class="mui-backdrop" v-show="isShowMes">
          <div class="tips-list">

            <div class="mui-card card_content padding">
              <div class="tips">工作提醒</div>
              <div class="flex justify-between padding border-bottom" @tap="tipsDetail('reminders');read1=true">
                <span>工作提醒</span>
                <span v-if="read1" class="color-blue mui-navigate-right">已阅读</span>
                <span v-else class="color-999 mui-navigate-right">未阅读</span>

              </div>
              <div class="flex justify-between padding border-bottom" @tap="tipsDetail('instruction');read2=true">
                <span>操作须知</span>
                <span v-if="read2" class="color-blue mui-navigate-right">已阅读</span>
                <span v-else class="color-999 mui-navigate-right">未阅读</span>
              </div>
              <div class="option">
                <button type="button" class="mui-btn" @click="isShowMes=false">关闭</button>
              </div>
            </div>

          </div>
        </div>-->

        <div class="screens mui-popover mui-popover-top">
          <div class="mui-segmented-control mui-segmented-control-inverted mui-segmented-control-primary" style="background-color: #fff;border-bottom: 1px solid #DCDCDC;">
            <a class="mui-control-item mui-active" @tap="sliderIndex=0"><span class="txt">全部</span></a>
            <a class="mui-control-item" @tap="sliderIndex=1"><span class="txt">已验收</span></a>
            <a class="mui-control-item" @tap="sliderIndex=2"><span class="txt">未验收</span></a>
          </div>
          <div class="content_ul">
            <div class="flex flex-wrap padding border-bottom" style="padding-right: 0;margin-right: -15px;min-height: 96px;">
              <div :class="['square-item', item.status == 4? 'bg-blue': '' , i == pageIndex ? 'active' : '']" v-for="(item, i) in sliderList" :key="i" @tap="checkInfo(item)">
                <img src="../img/gongzuopiao_duigou.png" v-if="item.status == 4" />
                <span v-else>{{item.index + 1}}</span>
              </div>
            </div>
            <div class="padding flex justify-around">
              <button type="button" class="mui-btn flex-sub" @tap="screen">关闭</button>
              <!--<button type="button" class="mui-btn flex-sub mui-btn-primary" @tap="getScreen">确定</button>-->
            </div>
          </div>
        </div>
      </div>
    </div>

    <script src="../../../js/mui.js"></script>
    <script src="../../../js/mui.pullToRefresh.js"></script>
    <script src="../../../js/mui.pullToRefresh.material.js"></script>
    <script src="../../../js/jquery-1.7.2.min.js"></script>
    <script src="../../../js/vue.js"></script>
    <!--<script src="../js/main.js"></script>-->
    <script src="../js/mkeyplus.base.js"></script>
    <script src="../../../js/mui.zoom.js"></script>
    <script src="../../../js/mui.previewimage.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/sqlite.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/indexDBs.js"></script>
    <script type="text/javascript">
      let lineType =null;
      var dbId =0;
      let db={};
      const dbName = 'myDBcheck'; //数据库
      const storeName = 'verifyList'; //仓库名
      mui.init()
      mui.previewImage()
      var ids = 1; //当前页面数据id
      let lineDetails= {};
      // var dict=dict
      if(window.plus) {
        plusready();
      } else {
        document.addEventListener('plusready', plusready, false);
      }
      let dict = {}
     async function plusready() {
        var self = plus.webview.currentWebview();
        console.log('idssss', self.projectTaskId)
        ids = self.projectTaskSensitiveId
        console.log(ids)
        vm.pageIndex = self.i
        vm.list = self.list
        vm.claimed = self.claimed
        dbId = self.dbId;
        mui.baseApp.getDict(['valueUnit', 'valueType', 'inputSymbol', 'wpTag']).then(res => {
          vm.dict = res
          dict = res
        })
        lineType = getSysInfo();
        vm.lineType = getSysInfo();
        // 打开数据库 const dbName = 'myDB', storeName = 'processPackage'
        await openDB(dbName, storeName, 1).then(res=>{
          console.log('111',res) 
          db=res;
        })
		
		// 是否离线
		if(!lineType){
			getLineData()
			// getCacheData()
		} else {
			// 有网有离线数据
			getDataByKey(db, storeName,dbId).then(res=>{
				console.log('是否有离线数据',res)
				if(res == undefined){
					getProject(ids)
					vm.isOnlineAndOfflineData = false
				} else {
					getLineData()
					vm.lineType = lineType = false
					vm.isOnlineAndOfflineData = true
				}
			})
		}
		
      }
      let vm = new Vue({
        el: '#container',
        data: {
		  isOnlineAndOfflineData: false,
          projectList: [],
          dict: dict,
          files: [],
          serverUrl: mui.baseApp.serverUrl,
          isShowMes: false,
          read1: false,
          read2: false,
          list: [],
          pageIndex: 0, // 当前所属所以
          sliderIndex: 0, //筛选分类索引
          acceptIng: false, ////是否正在验收
          detail: {},
          allWp: [], //当前基本工序加辅助工序
          currentIndex: 0, //当前基本工序加辅助工序所在索引
          claimed: 0 ,// 任务领取状态 0 未被领取 1 自己领取 2 他人领取
          lxDatas:{},
          listDatas:{},
          lineDetails:{},
          lineType:null,
        },
        computed: {
          sliderList() {
            return this.list.filter(item => {
              if(this.sliderIndex == 0) {
                return true
              } else if(this.sliderIndex == 1 && item.status == 4) { //以颜色
                return true
              } else if(this.sliderIndex == 2 && item.status != 4) { //未验收
                return true
              } else {
                return false
              }
            })
          }
        },
        created: function() {
          //        getProject(ids)
        },
        methods: {
          saveInfo() {
            let then=this;
            console.log('编辑数据', this.projectList)
            let projectList = JSON.parse(JSON.stringify(this.projectList))
            let arrys = projectList.map(res => {
              return {
                value: res.checkValue,
                files: res.checkFiles,
                remarks: res.checkRemarks,
                basicWpInputId: res.basicWpInputId,
                id: res.checkId,
                basicWpType: res.basicWpType,
                refInput: res.refInput
              }
            })
            console.log('xin行', arrys)
            // return false
            let parm = {
              stage: 5,
              inputs: arrys,
            }
            let ajaxName = 'sensitive'
            let currentIndex = vm.currentIndex
            let allWp = vm.allWp
            if(this.detail.position) { //辅助工序
              parm.projectTaskSubSensitiveId = vm.allWp[vm.currentIndex].projectTaskSubSensitiveId
              ajaxName = 'subSensitive'
            } else {
              parm.projectTaskSensitiveId = ids
            }
            console.log(parm)
            //辅助工序的切换不走接口  保存提交时参数
            let checkParm = JSON.parse(JSON.stringify(parm))
            checkParm.checkInputs = checkParm.inputs
            delete checkParm.inputs
            Object.assign(vm.allWp[vm.currentIndex], checkParm)
            
            plus.nativeUI.showWaiting('提交中')
            lineType = getSysInfo();
            vm.lineType = getSysInfo();
            if(!lineType || vm.isOnlineAndOfflineData){
              // 获取离线数据
              // getLineData()
              mui.confirm('当前是离线状态！是否需要保存当前编辑内容？','提示',['是','否'],function(item){
                console.log('对话框提示',item)
                if(item.index==0){
                  if(then.detail.position) {
                    lineDetails.subWps.forEach((item,i)=>{
                      if(item.projectTaskSubSensitiveId==then.detail.projectTaskSubSensitiveId){
                        lineDetails.subWps[i]=Object.assign(item,parm)
                        lineDetails.subWps[i].status=4
                        then.$set(lineDetails.subWps,i,Object.assign(item,parm))
                      }
                    })
                  }else{
                    lineDetails= Object.assign(lineDetails,parm)
                    // then.detail['status']=4
                    lineDetails.status=4
                    then.lineDetails.status=4
                    then.listDatas['status']=4
                  }
                   
                  console.log('编辑数据22000', JSON.stringify(then.lxDatas))
                  getUpdata(then.lxDatas,parm)
                }else{
                  // getDel(taskId)
                }
              })
                
               return
            }else{
				// lineDetails= Object.assign(lineDetails,parm)
				// 删除提交参数path
				parm.inputs.forEach((a,i)=>{
					a.files === null ? [] :
					a.files.forEach((b,i)=>{
						delete a.files[i].path;  
					})
				})
				if(parm.signInfo !== undefined){
					delete parm.signInfo.takeImg.path
				}
				mui.baseApp.httpRequst("post", "/app/api/project/execution/" + ajaxName + "/execution", parm, (data) => {
				  console.log('数据列表', data)
				  plus.nativeUI.closeWaiting();
				  // then.detail['status']=4
				  // then.listDatas['status']=4
				  // getUpdata(then.lxDatas)
				  mui.toast(data.msg)
				  this.acceptIng = false
				  this.list[this.pageIndex].status = 4
				   let detailPage = plus.webview.getWebviewById('./detail.html')
				  mui.fire(detailPage, 'back', {})
				  let wpPage = plus.webview.getWebviewById('./riskList.html')
				  if(wpPage) {
				    mui.fire(wpPage, 'back', {})
				  }
				  
				  let noId = false
				  parm.inputs.forEach(item => {
				    if(!item.id) {
				      noId = true
				    }
				  })
				  if(noId) {
				    if(!lineType){
				      getLineData('cancel')
				      return
				    }
				    getProject(ids, 'cancel')
				  }
				}, function() {
				  mui.toast("保存失败")
				  plus.nativeUI.closeWaiting();
				  console.log("获取数据失败");
				})
			}
            
          },
          upInfo() {
            lineType = getSysInfo();
            vm.lineType = getSysInfo();
            if(vm.currentIndex > 0) {
              vm.currentIndex--
              handleData({
                data: vm.allWp[vm.currentIndex]
              })
              return
            }
            this.pageIndex--
            ids = this.list[this.pageIndex].id
            if(!lineType){
              getLineData()
              return
            }
            getProject(ids)
          },
          nextInfo() {
            lineType = getSysInfo();
            vm.lineType = getSysInfo();
            if(vm.currentIndex + 1 < vm.allWp.length) {
              vm.currentIndex++
              handleData({
                data: vm.allWp[vm.currentIndex]
              })
              return
            }
            this.pageIndex++
            ids = this.list[this.pageIndex].id
            if(!lineType){
              getLineData()
              return
            }
            getProject(ids)
          },
          checkInfo(item) {
            lineType = getSysInfo();
            vm.lineType = getSysInfo();
            if(this.pageIndex == item.index) {
              mui.toast('当前风险')
              return
            }
            this.pageIndex = item.index
            ids = item.id
            if(!lineType){
              getLineData()
              mui('.screens').popover('toggle');
              return
            }
            getProject(ids)
            mui('.screens').popover('toggle');
          },
          //取消验收
          cancel() {
            lineType = getSysInfo();
            vm.lineType = getSysInfo();
            if(!lineType){
              getLineData("cancel")
              this.acceptIng = false
              return
            }
            getProject(ids, "cancel")
            this.acceptIng = false
          },
          inputShowText(obj, dict) {
            // console.log(obj)
            let type = dict.id.valueType[obj.typeId].value // 类型
            if(type == 'text') {
              return obj.value
            } else if(type == 'img') {
              return '无'
            } else if (type == 'boolean') {
              return '是否'
            } else {
              let unit = dict.id.valueUnit[obj.unitId].value // 单位
              let symbol = dict.id.inputSymbol[obj.typeSubId].value // 符号
              let valueArr = obj.value.split(",")
              let showText = ''
              switch(symbol) {
                case '>':
                  showText = '>' + valueArr[0] + unit
                  break;
                case '≥':
                  showText = '≥' + valueArr[0] + unit
                  break;
                case '<':
                  showText = '<' + valueArr[0] + unit
                  break;
                case '≤':
                  showText = '≤' + valueArr[0] + unit
                  break;
                case '=':
                  showText = '=' + valueArr[0] + unit
                  break;
                case '!=':
                  showText = '!=' + valueArr[0] + unit
                  break;
                case '()':
                  showText = '>' + valueArr[0] + unit + '  ' + '<' + valueArr[1] + unit
                  break;
                case '[]':
                  showText = '≥' + valueArr[0] + unit + '  ' + '≤' + valueArr[1] + unit
                  break;
                case '(]':
                  showText = '>' + valueArr[0] + unit + '  ' + '≤' + valueArr[1] + unit
                  break;
                case '[)':
                  showText = '≥' + valueArr[0] + unit + '  ' + '<' + valueArr[1] + unit
                  break;
                case ')(':
                  showText = '<' + valueArr[0] + unit + '  ' + '>' + valueArr[1] + unit
                  break;
                case '][':
                  showText = '≤' + valueArr[0] + unit + '  ' + '≥' + valueArr[1] + unit
                  break;
                case ')[':
                  showText = '<' + valueArr[0] + unit + '  ' + '≥' + valueArr[1] + unit
                  break;
                case '](':
                  showText = '≤' + valueArr[0] + unit + '  ' + '>' + valueArr[1] + unit
                  break;
                default:
                  showText = obj.value + unit
                  break
              }
              return showText
            }
          },
          delImg(index, i) {
            let self = this
            mui.confirm("是否删除", "提示", ["取消", "确认"], function(e) {
              //            console.log(_src)
              if(e.index) {
                self.projectList[index].checkFiles.splice(i, 1)
              }
            })
          },
          tipsDetail(type) {
            mui.baseApp.openWindow('../performTasks/carryoutTipsDetail.html?type=' + type)
          },
          camera(i) {
            let self = this
            lineType = getSysInfo();
            this.lineType = getSysInfo();
            mui.baseApp.chooseImg().then(res => {
              mui.baseApp.compressImage(res).then(path => {
                console.log(path)
                plus.nativeUI.showWaiting('上传中')
                if(!lineType){
                  self.projectList[i].checkFiles.push({
                    // fileId: data.id,
                    filePath: path,
                    // filename: data.fileName,
                    path: path
                  })
                  plus.nativeUI.closeWaiting()
                  return
                }
                mui.baseApp.upLoadFile(path, function(res) {
                  console.log(res)
                  let data = res.data
                  plus.nativeUI.closeWaiting()
                  mui.toast("上传成功")
                  self.projectList[i].checkFiles.push({
                    id: data.id,
                    filePath: data.fileDirectory,
                    filename: data.fileName,
                    path: path
                  })
                })
              })
            })
          },
          screen() {
            mui('.screens').popover('toggle');
          },
          getScreen() {
            mui('.screens').popover('toggle');
          },
        },
      })

      function getProject(ids, type) {
        plus.nativeUI.showWaiting('加载中')
        mui.baseApp.httpRequst("get", "/app/api/project/execution/sensitive/detail/" + ids, {}, function(data) {
          console.log('数据列表', data)
          plus.nativeUI.closeWaiting();
          let subWps = data.data.subWps || []
          let prefix = []; // 前置
          let suffix = []; // 后置
          subWps.forEach(item => {
            item.isReturn = data.data.isReturn 
            if(item.position == 1) {
              prefix.push(item)
            } else {
              suffix.push(item)
            }
          })
          delete data.data.subWps
          vm.allWp = prefix.concat([data.data]).concat(suffix)
          if(type != 'cancel') { // 取消保持原来的
            vm.currentIndex = 0
          }
          
          handleData({
            data: vm.allWp[vm.currentIndex]
          })
        }, function() {
             plus.nativeUI.closeWaiting()
          console.log("获取数据失败");
        })
      }
      function getUpdata(lxDatas,parm){
         updateDB(db, storeName,lxDatas).then(msg=>{
           console.log('离线保存',JSON.stringify(msg))
           plus.nativeUI.closeWaiting();
           if(msg.isTrusted){
              mui.toast("保存成功")
               vm.acceptIng = false
               vm.list[vm.pageIndex].status = 4
                let detailPage = plus.webview.getWebviewById('./detail.html')
               mui.fire(detailPage, 'back', {})
               let wpPage = plus.webview.getWebviewById('./riskList.html')
               if(wpPage) {
                 mui.fire(wpPage, 'back', {})
               }
               
               let noId = false
               parm.inputs.forEach(item => {
                 if(!item.id) {
                   noId = true
                 }
               })
           }else{
             mui.toast("保存失败")
           }
              
         })
       }
       function getCacheData(){
         getDataByKey(db, storeName,dbId).then(res=>{
           vm.lxDatas=res
           let data={}
           res.wpItemList.forEach(msg=>{
             if(msg.childs&&msg.childs.length>0){
               msg.childs.forEach(item=>{
                 if(item.childs&&item.childs.length>0){
                   item.childs.forEach(v=>{
                      console.log('ok3',v)
                     if(v.childs&&v.childs.length>0){
                       console.log('ok4',v.childs)
                     }
                     if(v.taskWps&&v.taskWps.length>0){
                        v.taskWps.forEach(c=>{
                          if(c.id==ids){
                            console.log('ccc',c.details)
                            vm.listDatas=c
                            data=c.details
                          }
                        })
                     }
                   })
                 }
                 if(item.taskWps&&item.taskWps.length>0){
                    item.taskWps.forEach(b=>{
                      if(b.id==ids){
                        console.log('bbb',b.details)
                        vm.listDatas=b
                        data=b.details
                      }
                    })
                 }
               })
             }
             if(msg.taskWps&&msg.taskWps.length>0){
                msg.taskWps.forEach(a=>{
                  if(a.id==ids){
                    console.log('aaa',a.details)
                    vm.listDatas=a
                    data=a.details
                  }
                })
             }
           })
           vm.lineDetails=data
           lineDetails=data
         })
       }
      //获取离线数据
      function getLineData(type){
        getDataByKey(db, storeName,dbId).then(res=>{
           plus.nativeUI.closeWaiting(); 
          console.log('获取离线数据',res)
          vm.lxDatas=res
          let data={}
          res&&res.sensitiveList&&res.sensitiveList.forEach(msg=>{
            if(msg.childs&&msg.childs.length>0){
              msg.childs.forEach(item=>{
                if(item.childs&&item.childs.length>0){
                  item.childs.forEach(v=>{
                     console.log('ok3',v)
                    if(v.childs&&v.childs.length>0){
                      console.log('ok4',v.childs)
                    }
                    if(v.taskWps&&v.taskWps.length>0){
                       v.taskWps.forEach(c=>{
                         if(c.id==ids){
                           console.log('ccc',c.details)
                           vm.listDatas=c
                           data=c.details
                         }
                       })
                    }
                  })
                }
                if(item.taskWps&&item.taskWps.length>0){
                   item.taskWps.forEach(b=>{
                     if(b.id==ids){
                       console.log('bbb',b.details)
                       vm.listDatas=b
                       data=b.details
                     }
                   })
                }
              })
            }
            if(msg.taskWps&&msg.taskWps.length>0){
               msg.taskWps.forEach(a=>{
                 if(a.id==ids){
                   console.log('aaa',a.details)
                   vm.listDatas=a
                   data=a.details
                 }
               })
            }
          })
          // vm.lineDetails=data
          lineDetails=data
          let datas ={...data}
             let subWps = datas.subWps || []
             let prefix = []; // 前置
             let suffix = []; // 后置
             subWps.forEach(item => {
               item.isReturn = datas.isReturn 
               if(item.position == 1) {
                 prefix.push(item)
               } else {
                 suffix.push(item)
               }
             })
             delete datas.subWps
             vm.allWp = prefix.concat([datas]).concat(suffix)
             if(type != 'cancel') { // 取消保持原来的
               vm.currentIndex = 0
             }
             
             handleData({
               data: vm.allWp[vm.currentIndex]
             })
        })
      }
      function handleData(data) {
        console.log(data)
        data = JSON.parse(JSON.stringify(data))
        let checkInputs = data.data.checkInputs
        let inputs = data.data.inputs
           
        let lists = data.data.checkInputs.map((res, i) => {
          let id = res.refInput.id
          let type = res.refInput.basicWpType
          res['checkValue'] = checkInputs[i] ? (checkInputs[i].value || '') : ''
          res['checkRemarks'] = checkInputs[i] ? (checkInputs[i].remarks || ''): ''
          res['checkFiles'] = checkInputs[i] ?  (checkInputs[i].files || []): []
          res['checkId'] = checkInputs[i] ? (checkInputs[i].id || ''): ''
          // 先清空值
          res['value'] = ''
          res['remarks'] = ''
          res['files'] = []
          for(let i=0;i<inputs.length;i++) { //获取执行时填写的值
            let obj = inputs[i]
            if(id == obj.refInput.id && type == obj.refInput.basicWpType) {
              res['value'] = obj.value || ''
              res['remarks'] = obj.remarks || ''
              res['files'] = obj.files || []
              break;
            }
          }
          return res
        })
        console.log('新数据列表12', lists)
        vm.projectList = lists
        vm.detail = data.data
      }
      function getSysInfo() {
          types = {};
          types[plus.networkinfo.CONNECTION_UNKNOW] = "未知";
          types[plus.networkinfo.CONNECTION_NONE] = "未连接网络";
          types[plus.networkinfo.CONNECTION_ETHERNET] = "有线网络";
          types[plus.networkinfo.CONNECTION_WIFI] = "WiFi网络";
          types[plus.networkinfo.CONNECTION_CELL2G] = "2G蜂窝网络";
          types[plus.networkinfo.CONNECTION_CELL3G] = "3G蜂窝网络";
          types[plus.networkinfo.CONNECTION_CELL4G] = "4G蜂窝网络";
       
          var str = types[plus.networkinfo.getCurrentType()];
          if (str == '未知' || str == '未连接网络') {
              return false;
          } else {
              return true;
          }
       
      }
      $(document).ready(function() {
        let height = document.documentElement.clientHeight
        //防止软键盘弹出底部按钮顶上来
        $(".mui-content").css('height', height + 'px')
      })
    </script>
  </body>

</html>